

/**
 * Created by yanghaibo on 2016/10/25.
 */
OrderDetailController = function () {

    // 获取订单详情
    this.getOrderDetail = function(orderId,orderType,newOrderStatus) {
        var serverUrl = App.serverUrl +　"app/order/getOrderDetail.do";
        var param  = {
            orderId: orderId,
            orderType: orderType
        }; // 参数
        var sucFunc = function (result) {            
            if (result && result.success) {
                // 后端返回成功
                var resultObj = result.resultObject;
                
                if (!resultObj) {
                    log4JS.info("getOrderDetail server resultObject is null. ");
                    return;
                }
                // resultObj.newOrderStatus=newOrderStatus;
                resultObj.newOrderStatus=resultObj.orderStatus
                // 渲染模板
                CommonUtil.render($("#orderDetailDiv"), "orderDetailTpl", resultObj);
                var refundStatus = resultObj.refundStatus;
                var orderTypes = resultObj.orderType;
                var hasInvoiced = resultObj.hasInvoiced;//发票的状态 0:未开,1开过
                var isRefunded = resultObj.isRefunded;//退款原因 0:没有 1:有过
                var orderPlatformSource = resultObj.orderPlatformSource//获取订单来源
                var cancellationAmount = resultObj.cancellationAmount//获取核销金额
                if(orderPlatformSource == "5" && refundStatus !='1'&& refundStatus !='2' && refundStatus !='3'){//判断退款展示按钮
                    CommonUtil.showElement("#xmg_tk");
                }else{
                   // CommonUtil.hideElement("#xmg_tk");
                    
                }
                if(orderTypes == 1){//消费-收银订单
                    CommonUtil.hideElement("#xmg_chf");
                    CommonUtil.hideElement("#xmg_psf");
                    CommonUtil.hideElement("#xmg_fwf");
                    CommonUtil.hideElement("#xmg_qtfy");
                    CommonUtil.hideElement("#xmg_zh");
                    CommonUtil.hideElement("#xmg_qch");
                    CommonUtil.hideElement("#xmg_cyorderid");
                    //储值
                    CommonUtil.hideElement("#xmg_czxq");
                    //书页
                    CommonUtil.hideElement("#xmg_xsy");
                    //外卖
                    CommonUtil.hideElement("#xmg_shrdhbz");
                    //预约点餐
                    CommonUtil.hideElement("#xmg_yydc");
                    if(cancellationAmount<=0){
                        // 订单明细
                        CommonUtil.hideElement("#xmg_orderMxDcd");
                        CommonUtil.hideElement("#xmg_spqdk");
                    }
                    
                    //发票抬头
                    CommonUtil.hideElement("#xmg_fpxx");
                    // 配送信息
                    CommonUtil.hideElement("#xmg_psxx");
                }else if(orderTypes == 2){//储值订单
                    CommonUtil.hideElement("#xmg_ddje");
                    CommonUtil.hideElement("#xmg_chf");
                    CommonUtil.hideElement("#xmg_psf");
                    CommonUtil.hideElement("#xmg_fwf");
                    CommonUtil.hideElement("#xmg_qtfy");
                    CommonUtil.hideElement("#xmg_spqdk");
                    CommonUtil.hideElement("#xmg_yhje");
                    CommonUtil.hideElement("#xmg_mljg");
                    CommonUtil.hideElement("#xmg_zh");
                    CommonUtil.hideElement("#xmg_qch");
                    //明细模块
                    CommonUtil.hideElement("#xmg_sy");
                    CommonUtil.hideElement("#xmg_shrdhbz");
                    CommonUtil.hideElement("#xmg_yydc");
                    CommonUtil.hideElement("#xmg_cyorderid");
                    //发票抬头
                    CommonUtil.hideElement("#xmg_fpxx");
                    // 配送信息
                    CommonUtil.hideElement("#xmg_psxx");
                
                }else if(orderTypes == 3){//消费-点餐订单
                    CommonUtil.hideElement("#xmg_chf");
                    CommonUtil.hideElement("#xmg_psf");
                    CommonUtil.hideElement("#xmg_fwf");
                    CommonUtil.hideElement("#xmg_qtfy");
                    CommonUtil.hideElement("#xmg_spqdk");
                    CommonUtil.hideElement("#xmg_cyorderid");
                    //储值详情
                    CommonUtil.hideElement("#xmg_czxq");
                    //外卖点餐
                    CommonUtil.hideElement("#xmg_shr");
                    CommonUtil.hideElement("#xmg_lxdh");
                    //预约点餐
                    CommonUtil.hideElement("#xmg_yydc");
                    //发票抬头
                    CommonUtil.hideElement("#xmg_fpxx");
                    // 配送信息
                    CommonUtil.hideElement("#xmg_psxx");
                
                }else if(orderTypes == 4){//消费-桌边付订单
                    CommonUtil.hideElement("#xmg_chf");
                    CommonUtil.hideElement("#xmg_psf");
                    CommonUtil.hideElement("#xmg_qtfy");
                    CommonUtil.hideElement("#xmg_spqdk");
                    CommonUtil.hideElement("#xmg_zh");
                    CommonUtil.hideElement("#xmg_qch");
                    //储值详情
                    CommonUtil.hideElement("#xmg_czxq");
                    //外卖点餐
                    CommonUtil.hideElement("#xmg_shr");
                    CommonUtil.hideElement("#xmg_lxdh");
                    //预约点餐
                    CommonUtil.hideElement("#xmg_yydc");
                    //发票抬头
                    CommonUtil.hideElement("#xmg_fpxx");
                    // 配送信息
                    CommonUtil.hideElement("#xmg_psxx");

                }else if(orderTypes == 5){//消费-pos点餐订单
                    CommonUtil.hideElement("#xmg_chf");
                    CommonUtil.hideElement("#xmg_psf");
                    CommonUtil.hideElement("#xmg_fwf");
                    CommonUtil.hideElement("#xmg_qtfy");
                    CommonUtil.hideElement("#xmg_spqdk");
                    CommonUtil.hideElement("#xmg_cyorderid");
                    //储值详情
                    CommonUtil.hideElement("#xmg_czxq");
                    //外卖点餐
                    CommonUtil.hideElement("#xmg_shr");
                    CommonUtil.hideElement("#xmg_lxdh");
                    //预约点餐
                    CommonUtil.hideElement("#xmg_yydc");
                    //发票抬头
                    CommonUtil.hideElement("#xmg_fpxx");
                    // 配送信息
                    CommonUtil.hideElement("#xmg_psxx");

                }else if(orderTypes == 6){//外卖
                    CommonUtil.hideElement("#xmg_fwf");
                    CommonUtil.hideElement("#xmg_qtfy");
                    CommonUtil.hideElement("#xmg_spqdk");
                    CommonUtil.hideElement("#xmg_mljg");
                    CommonUtil.hideElement("#xmg_zh");
                    CommonUtil.hideElement("#xmg_qch");
                    CommonUtil.hideElement("#xmg_cyorderid");
                    //储值详情
                    CommonUtil.hideElement("#xmg_czxq");
                    //预约点餐
                    CommonUtil.hideElement("#xmg_yydc");
                        if(hasInvoiced == 0){
                            //发票抬头
                            CommonUtil.hideElement("#xmg_fpxx");
                        }
                    $("#xmg_fpxx .title").toggleClass("fold");//默认关闭发票信息
                    $("#xmg_psxx .title").toggleClass("fold");//默认关闭配送信息
                }else if(orderTypes == 7){//预约点餐订单
                    CommonUtil.hideElement("#xmg_psf");
                    CommonUtil.hideElement("#xmg_spqdk");
                    CommonUtil.hideElement("#xmg_mljg");
                    CommonUtil.hideElement("#xmg_zh");
                    CommonUtil.hideElement("#xmg_syyxing");
                    CommonUtil.hideElement("#xmg_cyorderid");
                    //储值详情
                    CommonUtil.hideElement("#xmg_czxq");
                    //外卖点餐
                    CommonUtil.hideElement("#xmg_shrdhbz");
                    //发票抬头
                    CommonUtil.hideElement("#xmg_fpxx");
                    // 配送信息
                    CommonUtil.hideElement("#xmg_psxx");
                }else{}
                if (refundStatus == 2 || refundStatus == 3) {
                    debugger
                    // 显示退款层
                    CommonUtil.showElement("#orderDetailPage .page-body .refund");
                    // 获取退款信息
                    CommonUtil.render($("#orderRefundDiv"), "orderRefundTpl", resultObj);

                } else {
                    CommonUtil.hideElement("#orderDetailPage .page-body .refund");
                    $("#orderRefundDiv").empty();                
                }                
            } else {
                DialogUtil.dialogWarn(result.msg);
            }            
        };

        CommonUtil.sendJsonpRequest({
            url: serverUrl,
            params: param,
            success: sucFunc
        });
    };
    //获取退款
    this.getOrderDetailRefund = function(orderId,shopId,refundMoney,refundReason,inputPwd,orderType,newOrderStatus) {
       common.loading();
        var postData = {
            orderId : orderId,
            shopId: shopId,
            refundMoney : refundMoney,
            refundReason : refundReason,
            inputPwd : inputPwd
        };
        var serverUrl = App.serverUrl +　"app/order/appRefundOrder.do";
        var sucFunc = function(result) {
            var refundMassges = result.resultObject.msg;
            var skWay = $("#xmg_hqskfs").html();//获取支付方式
            if(result.resultObject.success&& (result.resultObject!="" || result.resultObject!=null)){
                common.closeLoading();
                $.router.load("order_result_success.html?refundMoney="+refundMoney+"&skWay="+skWay+"&orderId="+orderId+"&orderType="+orderType+"&newOrderStatus=2");//退款成功页面
            }else{
                 common.closeLoading();
                $.router.load("order_result_failed.html?refundMoney="+refundMoney+"&skWay="+skWay+"&refundMassges="+refundMassges+"&orderId="+orderId+"&orderType="+orderType+"&newOrderStatus="+newOrderStatus);//退款失败页面
            }
            
        }
        console.info(JSON.stringify(postData));
        AppUtil.call(AppUtil.APIS.SEND_HTTP_REQUEST,
            {
                type: "POST",
                url: serverUrl,
                data: JSON.stringify(postData)
            }, sucFunc);
        }

};